.class Lcom/waiqin365/base/print/c;
.super Ljava/lang/Thread;


# instance fields
.field final synthetic a:Lcom/waiqin365/base/print/b;

.field private final b:Landroid/bluetooth/BluetoothServerSocket;


# direct methods
.method public constructor <init>(Lcom/waiqin365/base/print/b;)V
    .locals 4

    iput-object p1, p0, Lcom/waiqin365/base/print/c;->a:Lcom/waiqin365/base/print/b;

    invoke-direct {p0}, Ljava/lang/Thread;-><init>()V

    const/4 v0, 0x0

    :try_start_0
    invoke-static {p1}, Lcom/waiqin365/base/print/b;->a(Lcom/waiqin365/base/print/b;)Landroid/bluetooth/BluetoothAdapter;

    move-result-object v1

    const-string/jumbo v2, "BTPrinter"

    invoke-static {}, Lcom/waiqin365/base/print/b;->i()Ljava/util/UUID;

    move-result-object v3

    invoke-virtual {v1, v2, v3}, Landroid/bluetooth/BluetoothAdapter;->listenUsingInsecureRfcommWithServiceRecord(Ljava/lang/String;Ljava/util/UUID;)Landroid/bluetooth/BluetoothServerSocket;
    :try_end_0
    .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v0

    :goto_0
    iput-object v0, p0, Lcom/waiqin365/base/print/c;->b:Landroid/bluetooth/BluetoothServerSocket;

    return-void

    :catch_0
    move-exception v1

    const-string/jumbo v2, "BluetoothService"

    const-string/jumbo v3, "listen() failed"

    invoke-static {v2, v3, v1}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I

    goto :goto_0
.end method


# virtual methods
.method public cancel()V
    .locals 3

    const-string/jumbo v0, "BluetoothService"

    new-instance v1, Ljava/lang/StringBuilder;

    invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V

    const-string/jumbo v2, "cancel "

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    invoke-static {v0, v1}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

    :try_start_0
    iget-object v0, p0, Lcom/waiqin365/base/print/c;->b:Landroid/bluetooth/BluetoothServerSocket;

    if-eqz v0, :cond_0

    iget-object v0, p0, Lcom/waiqin365/base/print/c;->b:Landroid/bluetooth/BluetoothServerSocket;

    invoke-virtual {v0}, Landroid/bluetooth/BluetoothServerSocket;->close()V
    :try_end_0
    .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0

    :cond_0
    :goto_0
    return-void

    :catch_0
    move-exception v0

    const-string/jumbo v1, "BluetoothService"

    const-string/jumbo v2, "close() of server failed"

    invoke-static {v1, v2, v0}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I

    goto :goto_0
.end method

.method public run()V
    .locals 4

    const-string/jumbo v0, "BluetoothService"

    new-instance v1, Ljava/lang/StringBuilder;

    invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V

    const-string/jumbo v2, "BEGIN mAcceptThread"

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    invoke-static {v0, v1}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

    const-string/jumbo v0, "AcceptThread"

    invoke-virtual {p0, v0}, Lcom/waiqin365/base/print/c;->setName(Ljava/lang/String;)V

    :cond_0
    :goto_0
    iget-object v0, p0, Lcom/waiqin365/base/print/c;->a:Lcom/waiqin365/base/print/b;

    invoke-static {v0}, Lcom/waiqin365/base/print/b;->b(Lcom/waiqin365/base/print/b;)I

    move-result v0

    const/4 v1, 0x3

    if-eq v0, v1, :cond_1

    iget-object v0, p0, Lcom/waiqin365/base/print/c;->b:Landroid/bluetooth/BluetoothServerSocket;

    if-eqz v0, :cond_1

    const-string/jumbo v0, "AcceptThread\u7ebf\u7a0b\u8fd0\u884c"

    const-string/jumbo v1, "\u6b63\u5728\u8fd0\u884c......"

    invoke-static {v0, v1}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

    :try_start_0
    iget-object v0, p0, Lcom/waiqin365/base/print/c;->b:Landroid/bluetooth/BluetoothServerSocket;

    invoke-virtual {v0}, Landroid/bluetooth/BluetoothServerSocket;->accept()Landroid/bluetooth/BluetoothSocket;
    :try_end_0
    .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v0

    if-eqz v0, :cond_0

    iget-object v1, p0, Lcom/waiqin365/base/print/c;->a:Lcom/waiqin365/base/print/b;

    monitor-enter v1

    :try_start_1
    iget-object v2, p0, Lcom/waiqin365/base/print/c;->a:Lcom/waiqin365/base/print/b;

    invoke-static {v2}, Lcom/waiqin365/base/print/b;->b(Lcom/waiqin365/base/print/b;)I

    move-result v2

    packed-switch v2, :pswitch_data_0

    :goto_1
    monitor-exit v1

    goto :goto_0

    :catchall_0
    move-exception v0

    monitor-exit v1
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0

    throw v0

    :catch_0
    move-exception v0

    const-string/jumbo v1, "BluetoothService"

    const-string/jumbo v2, "accept() failed"

    invoke-static {v1, v2, v0}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I

    :cond_1
    const-string/jumbo v0, "BluetoothService"

    const-string/jumbo v1, "END mAcceptThread"

    invoke-static {v0, v1}, Landroid/util/Log;->i(Ljava/lang/String;Ljava/lang/String;)I

    return-void

    :pswitch_0
    :try_start_2
    iget-object v2, p0, Lcom/waiqin365/base/print/c;->a:Lcom/waiqin365/base/print/b;

    invoke-virtual {v0}, Landroid/bluetooth/BluetoothSocket;->getRemoteDevice()Landroid/bluetooth/BluetoothDevice;

    move-result-object v3

    invoke-virtual {v2, v0, v3}, Lcom/waiqin365/base/print/b;->a(Landroid/bluetooth/BluetoothSocket;Landroid/bluetooth/BluetoothDevice;)V
    :try_end_2
    .catchall {:try_start_2 .. :try_end_2} :catchall_0

    goto :goto_1

    :pswitch_1
    :try_start_3
    invoke-virtual {v0}, Landroid/bluetooth/BluetoothSocket;->close()V
    :try_end_3
    .catch Ljava/io/IOException; {:try_start_3 .. :try_end_3} :catch_1
    .catchall {:try_start_3 .. :try_end_3} :catchall_0

    goto :goto_1

    :catch_1
    move-exception v0

    :try_start_4
    const-string/jumbo v2, "BluetoothService"

    const-string/jumbo v3, "Could not close unwanted socket"

    invoke-static {v2, v3, v0}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I
    :try_end_4
    .catchall {:try_start_4 .. :try_end_4} :catchall_0

    goto :goto_1

    :pswitch_data_0
    .packed-switch 0x0
        :pswitch_1
        :pswitch_0
        :pswitch_0
        :pswitch_1
    .end packed-switch
.end method
